package com.teamone.etl.apimanager.controller;


import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.github.pagehelper.PageInfo;
import com.teamone.etl.apimanager.entity.ApiCharge;
import com.teamone.etl.apimanager.request.BaseQuery;
import com.teamone.etl.apimanager.service.ApiChargeService;
import com.teamone.etl.apimanager.valid.AddGroup;
import com.teamone.etl.apimanager.valid.UpdateGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 接口计费表(ApiCharge)表控制层
 *
 * @author makejava
 * @since 2021-01-20 18:32:04
 */
@RestController
@RequestMapping("apiCharge")
public class ApiChargeController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private ApiChargeService apiChargeService;

    /**
     * 查询接口计费方式列表
     * @param baseQuery 分页对象
     * @return 查询结果
     */
    @PostMapping
    public R<PageInfo<ApiCharge>> selectAll(@RequestBody BaseQuery baseQuery){
        return success(apiChargeService.selectAll(baseQuery));
    }

    /**
     * 新增接口计费方式
     * @param apiCharge 接口计费方式对象
     * @return 新增结果
     */
    @PostMapping("save")
    public R saveOne(@RequestBody @Validated(AddGroup.class) ApiCharge apiCharge){
        apiChargeService.saveOne(apiCharge);
        return success(true);
    }

    /**
     * 根据费方式id删除
     * @param id 接口计费方式id
     * @return 删除结果
     */
    @DeleteMapping("{id}")
    public R logicDeleteById(@PathVariable Integer id){
        apiChargeService.logicDeleteById(id);
        return success(true);
    }

    /**
     * 修改接口计费规则
     * @param apiCharge 接口计费规则对象
     * @return 执行结果
     */
    @PutMapping
    public R updateOne(@RequestBody @Validated(UpdateGroup.class) ApiCharge apiCharge){
        apiChargeService.updateOne(apiCharge);
        return success(true);
    }

}